
import sys,os,dis
import os.path
sys.path.append(os.getcwd() + '/out/Debug/')
import TestHir
def myfunc():
    while True:
        a += 1
    return a



def doFile(fileName):
    print 'handling ' + fileName
    with open(fileName,'r') as f:
        content = f.read()
    exec content
    dis.dis(test)
    print test
    TestHir.compile(test)

def doDir(fileName):
    files = os.listdir(fileName)
    for myfile in files:
        if myfile.startswith('.'):
            continue
        doFile(os.path.join(fileName, myfile))

def main():
    if len(sys.argv) <= 1:
        TestHir.compile(myfunc)
        return

    fileName = sys.argv[1]
    if os.path.isfile(fileName):
        doFile(fileName)
    else:
        doDir(fileName)

if __name__ == '__main__':
    main()
